<!DOCTYPE HTML>
<html>
<head>
  <meta charset="utf-8">
  
  <title>5-机器视觉处理 | ChenBlue | 飞雪连天射白鹿 笑书神侠倚碧鸳</title>

  
  <meta name="author" content="ChenBlue">
  

  
  <meta name="description" content="学习笔记">
  

  
  
  <meta name="keywords" content="ROS">
  

  <meta id="viewport" name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no, minimal-ui">
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">

  <meta property="og:title" content="5-机器视觉处理"/>

  <meta property="og:site_name" content="ChenBlue"/>

  
  <meta property="og:image" content="/blog/favicon.ico"/>
  

  <link href="/blog/favicon.ico" rel="icon">
  <link rel="alternate" href="/blog/atom.xml" title="ChenBlue" type="application/atom+xml">
  <link rel="stylesheet" href="/blog/css/style.css" media="screen" type="text/css">
<meta name="generator" content="Hexo 5.4.0"></head>


<body>
<div class="blog">
  <div class="content">

    <header>
  <div class="site-branding">
    <h1 class="site-title">
      <a href="/blog/">ChenBlue</a>
    </h1>
    <p class="site-description">飞雪连天射白鹿 笑书神侠倚碧鸳</p>
  </div>
  <nav class="site-navigation">
    <ul>
      
    </ul>
  </nav>
</header>

    <main class="site-main posts-loop">
    <article>

  
    
    <h3 class="article-title"><span>5-机器视觉处理</span></h3>
    
  

  <div class="article-top-meta">
    <span class="posted-on">
      <a href="/blog/2021/04/12/5-机器视觉处理/" rel="bookmark">
        <time class="entry-date published" datetime="2021-04-12T12:39:03.000Z">
          2021-04-12
        </time>
      </a>
    </span>
  </div>


  

  <div class="article-content">
    <div class="entry">
      
        <h1 id="ROS-摄像头驱动及数据接口"><a href="#ROS-摄像头驱动及数据接口" class="headerlink" title="ROS 摄像头驱动及数据接口"></a>ROS 摄像头驱动及数据接口</h1><p><strong>安装启动摄像头</strong></p>
<pre class="language-none"><code class="language-none">sudo apt-get install ros-melodic-usb-cam
roslaunch usb_cam usb_cam-test.launch
rqt_image_view</code></pre>

<h2 id="摄像头参数的标定"><a href="#摄像头参数的标定" class="headerlink" title="摄像头参数的标定"></a>摄像头参数的标定</h2><p><strong>安装标定的功能包</strong></p>
<pre class="language-none"><code class="language-none">sudo apt-get install ros-melodic-camera-calibration</code></pre>
<h3 id="摄像头标定流程"><a href="#摄像头标定流程" class="headerlink" title="摄像头标定流程"></a>摄像头标定流程</h3><p><strong>启动摄像头</strong></p>
<pre class="language-none"><code class="language-none">roslaunch robot_vision usb_cam.launch</code></pre>

<p><strong>启动标定包</strong></p>
<pre class="language-none"><code class="language-none">rosrun camera_calibration cameracalibrator.py --size 8x6--square 0.024 image:&#x3D;&#x2F;usb_cam&#x2F;image_raw camera:&#x3D;&#x2F;usb_cam</code></pre>
<ol>
<li>size:标定棋盘格的内部角点个数，这里使用的棋盘一共有六行，每行有8个内部角点;</li>
<li>square:这个参数对应每个棋盘格的边长，单位是米;</li>
<li>image和camera:设置摄像头发布的图像话题。</li>
</ol>
<h1 id="ROS-OpenCV-图像处理方法及案例"><a href="#ROS-OpenCV-图像处理方法及案例" class="headerlink" title="ROS + OpenCV 图像处理方法及案例"></a>ROS + OpenCV 图像处理方法及案例</h1><p><strong>安装 OpenCV</strong></p>
<pre class="language-none"><code class="language-none">sudo apt-get install ros-melodic-vision-opencv libopencv-dev python-opencv</code></pre>

<pre class="language-none"><code class="language-none">graph LR
subgraph ROS
handler(&quot;CvBridge&quot;)--&gt;handler2(&quot;ROS Image Message&quot;)
handler2(&quot;ROS Image Message&quot;)--&gt;handler(&quot;CvBridge&quot;)
end
subgraph OpenCV
start(&quot;Opencv ipiimage&quot;)--&gt;handler(&quot;CvBridge&quot;)
handler(&quot;CvBridge&quot;)--&gt;start(&quot;Opencv ipiimage&quot;)
end</code></pre>

<p>ROS + OpenCV 最重要的就是 CvBridge 。通过这个将图像进行转化。所有的图像处理都是用opencv去处理的。</p>
<blockquote>
<p>imgmsg_to_cv2() : 将 ROS 图像消息转换成 OpenCV 图像数据</p>
<p>cv2_to_imgmsg(): 将 OpenCV格式的图像数据转换成 ROS 图像消息</p>
</blockquote>
<h1 id="ROS-Tensorflow-物体识别方法及案例"><a href="#ROS-Tensorflow-物体识别方法及案例" class="headerlink" title="ROS + Tensorflow 物体识别方法及案例"></a>ROS + Tensorflow 物体识别方法及案例</h1><p><strong>安装 TensorFlow</strong></p>
<pre class="language-none"><code class="language-none">sudo apt-get install python-pip python-dev python-virtualenv

virtualenv --system-site-packages ~&#x2F;tensorflow

source ~&#x2F;tensorflow&#x2F;bin&#x2F;activate

easy_install -U pip

pip install --upgrade tensorflow</code></pre>
<p><strong>安装功能包</strong></p>
<pre class="language-none"><code class="language-none">cd ~&#x2F;catkin_ws&#x2F;src

git clone https:&#x2F;&#x2F;github.com&#x2F;Kukanani&#x2F;vision msgs.git

git clone https:&#x2F;&#x2F;github.com&#x2F;osrf&#x2F;tensorflow_object_detector.git</code></pre>

<p><strong>物体识别</strong></p>
<pre class="language-none"><code class="language-none">roslaunch tensorflow_object_detector usb_cam_detector.launch</code></pre>



      
    </div>

  </div>

  <div class="article-footer">
    <div class="article-meta pull-left">

    
      

    <span class="post-categories">
      <i class="icon-categories"></i>
        <a href="/blog/categories/ROS-学习笔记/">ROS 学习笔记</a>
    </span>
    

    
    

    <span class="post-tags">
      <i class="icon-tags"></i>
        <a href="/blog/tags/ROS/">ROS</a>
    </span>
    

    </div>

    
  </div>
</article>

  









    </main>

    <footer class="site-footer">
  <p class="site-info">
    Proudly powered by <a href="https://hexo.io/" target="_blank">Hexo</a> and
    Theme by <a href="https://github.com/CodeDaraW/Hacker" target="_blank">Hacker</a>
    </br>
    
    &copy; 2023 ChenBlue
    
  </p>
</footer>
    
    
  </div>
</div>
</body>
</html>